/*
 * Copyright (c) 2025 HiSilicon (Shanghai) Technologies Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef OT_MOTOR_H
#define OT_MOTOR_H

#include "ot_af_common.h"

typedef enum {
    OT_MOTOR_STATE_IDLE,
    OT_MOTOR_STATE_RUNNING,
    OT_MOTOR_STATE_FINISHED,
    OT_MOTOR_STATE_ERROR,
    OT_MOTOR_STATE_BUTT
} OT_AF_MOTOR_State;

typedef struct {
    td_u32 minCode;  /* 最小量程 */
    td_u32 maxCode;  /* 最大量程 */
    td_u32 minSpeed; /* 最小速度 */
    td_u32 maxSpeed; /* 最大速度 */
} OT_AF_FocusMotorCapability;

typedef struct {
    td_float minZoom;
    td_float maxZoom;
    td_u32 minSpeed; /* 最小速度 */
    td_u32 maxSpeed; /* 最大速度 */
} OT_AF_ZoomMotorCapability;

typedef struct {
    /* 待定 */
    td_u32 minCode;  /* 最小量程 */
    td_u32 maxCode;  /* 最大量程 */
} OT_AF_ApertureMotorCapability;

typedef struct {
    td_s32 curFocusCode;     /* 当前对焦马达code */
    td_s32 targetFocusCode;  /* 目标对焦马达code */
} OT_MOTOR_ZoomTrackingInfo;

typedef struct {
    td_s32 (*init)(td_void);
    td_s32 (*deinit)(td_void);
    td_s32 (*getMotorCapability)(OT_AF_ApertureMotorCapability *cap);
    td_s32 (*handleMotor)(td_s32 code, td_bool isSync);
    td_s32 (*queryState)(OT_AF_MOTOR_State *state);
    td_s32 (*getCurrentCode)(td_s32 *code);
    td_s32 (*resetDevice)(td_void);
} OT_AF_ApertureMotorAlgIntf;

typedef struct {
    td_s32 (*init)(td_void);
    td_s32 (*deinit)(td_void);
    td_s32 (*getMotorCapability)(OT_AF_FocusMotorCapability *cap);
    td_s32 (*setMotorSpeed)(td_s32 speed);
    td_s32 (*getMotorSpeed)(td_s32 *speed);
    td_s32 (*handleMotor)(td_s32 code, td_bool isSync);
    td_s32 (*queryState)(OT_AF_MOTOR_State *state);
    td_s32 (*getCurrentCode)(td_s32 *code);
    td_s32 (*resetDevice)(td_void);
} OT_AF_FocusMotorAlgIntf;

typedef struct {
    td_s32 (*init)(td_void);
    td_s32 (*deinit)(td_void);
    td_s32 (*getMotorCapability)(OT_AF_ZoomMotorCapability *cap);
    td_s32 (*setMotorSpeed)(td_s32 speed);
    td_s32 (*getMotorSpeed)(td_s32 *speed);
    td_s32 (*handleMotor)(const OT_AF_ZoomInfo *zoomInfo, td_bool isSync);
    td_s32 (*handleMotorTracking)(const OT_AF_ZoomInfo *zoomInfo,
        const OT_MOTOR_ZoomTrackingInfo *trackingInfo, td_bool isSync);
    td_s32 (*queryState)(OT_AF_MOTOR_State *state);
    td_s32 (*getCurrentZoom)(td_float *zoom);
    td_s32 (*resetDevice)(td_void);
} OT_AF_ZoomMotorAlgIntf;

typedef struct {
    td_s32 (*init)(td_void);
    td_s32 (*deinit)(td_void);
    td_s32 (*handleMotor)(td_s32 code, td_bool isSync);
    td_s32 (*queryState)(OT_AF_MOTOR_State *state);
    td_s32 (*getCurrentCode)(td_s32 *code);
    td_s32 (*resetDevice)(td_void);
} OT_AF_IRMotorAlgIntf;

#endif
